import mongoose, { Document, Schema } from "mongoose";

// 定义商品接口
export interface IProduct extends Document {
    title: string; // 标题
    description?: string; // 描述
    comment?: string; // 评价
    categories: string[]; // 分类
    tags: string[]; // 标签
    price: number; // 价格
    canBalanceBuy: boolean; //是否允许积分购买
    needsBalance: number; // 所需积分
    stock: number; // 库存
    addDraws: number //增加抽奖次数
    images: string[]; // 商品图片 URL 列表
    createdAt: string; // 创建时间
    updatedAt: string; // 更新时间
}

// 创建商品 Schema
const ProductSchema: Schema = new Schema({
    title: { type: String, required: true },
    description: { type: String },
    comment: { type: String, }, // 
    categories: [{ type: String }],
    tags: [{ type: String }],
    price: { type: Number, required: true },
    canBalanceBuy: { type: Boolean, default: false },
    needsBalance: { type: Number },
    stock: { type: Number, required: true },
    addDraws: { type: Number, default: 0 },
    images: [{ type: String }],
    createdAt: { type: String },
    updatedAt: { type: String },
});

// 创建并导出 Product 模型
export default mongoose.model<IProduct>("Product", ProductSchema);
